from bge import logic
from bge import events

def Player():
	cont = logic.getCurrentController()
	obj = cont.owner
	
	motion = cont.actuators['Motion']
	
	key = logic.keyboard.events
	kbleft = key[events.LEFTARROWKEY]
	kbright = key[events.RIGHTARROWKEY]
	kbup = key[events.UPARROWKEY]
	kbdown = key[events.DOWNARROWKEY]
	
	def Init():
		if not 'init' in obj:
			obj['init'] = 1
	
	def Update():
	
		movespd = 0.2
		mx = 0.0
		my = 0.0
		
		if kbleft > 0:
			mx = -movespd
		elif kbright > 0:
			mx = movespd
		
		if kbup > 0:
			my = movespd
		elif kbdown > 0:
			my = -movespd
			
		pos = obj.position	# Get the Player's current position
		topos = pos.copy()	# Make a copy of the Player's current position
		topos.x += mx		# And offset the copy by the movement value for the X-axis
		
		if obj.rayCast(topos, pos, 0, 'wall', 1, 1)[0] != None:	# We just collided with something on the X-axis
			mx = 0	# So stop movement on the X-axis
			print("Zderzenie z osią X")
			
			
		if obj.rayCast(topos, pos, 0, 'ball', 1, 1)[0] != None:	# We just collided with something on the Y-axis
			my = 0  # So stop movement on the Y-axis
			mx = 0
			print("Zderzenie z Kula")
			
			
		pos = obj.position	# Get the Player's current position
		topos = pos.copy()	# Make a copy of the Player's current position
		topos.y += my		# And offset the copy by the movement value for the Y-axis

		if obj.rayCast(topos, pos, 0, 'wall', 1, 1)[0] != None:	# We just collided with something on the Y-axis
			my = 0  # So stop movement on the Y-axis
		
<<<<<<< .mine
		motion.dLoc = [mx, my+0.01, 0.0]
=======
		motion.dLoc = [mx, my, 0.0	]
>>>>>>> .r6
		cont.activate(motion)
			
	Init()
	Update()
	
def Icopsphere__():
	cont = logic.getCurrentController()
	obj = cont.owner
	print(obj)
	motion = cont.actuators['Motion']
	speed = motion.dLoc[1]
	
	player = logic.getPlayer()
	print(player)
	
	def Update():
		mx = 0.1
		pos = obj.position	# Get the Player's current position
		topos = pos.copy()	# Make a copy of the Player's current position
		topos.x += mx		# And offset the copy by the movement value for the X-axis
		
		
		
		print(pos)
		
		if obj.rayCast(topos, pos, 0, 'wall', 1, 1)[0] != None:	# We just collided with something on the X-axis
			mx = mx*(-1) 	# So stop movement on the X-axis
			#print("Zderzenie z osią X")
		
		motion.dLoc = [mx, speed, 0.0]	
		cont.activate(motion)
	Update()
	
	
